package fun.sanguo.utils.sqlBuilder;

import org.apache.ibatis.jdbc.SQL;
import fun.sanguo.model.entity.interact.InteractPersonageViewEntity;
import fun.sanguo.model.enums.DelFlagEnums;

/**
 * 互动-人物浏览记录 sql语句生成类
 *
 * @author ZYP
 * @date 2023-10-13
 */
public class SqlBuilderInteractPersonageView {

    /**
     * 人物浏览记录表-新增
     *
     * @param interactPersonageViewEntity
     * @return
     */
    public String insert(InteractPersonageViewEntity interactPersonageViewEntity) {
        // 已存在则更新
        return new SQL() {{
            INSERT_INTO("INTERACT_PERSONAGE_VIEW");
            VALUES("user_id", "#{userId}");
            VALUES("user_ip", "#{userIp}");
            VALUES("personage_id", "#{personageId}");
            VALUES("view_time", "#{viewTime}");
            // 通用字段
            VALUES("id", "#{id}");
            VALUES("create_by", "#{createBy}");
            VALUES("create_time", "#{createTime}");
            VALUES("update_by", "#{updateBy}");
            VALUES("update_time", "#{updateTime}");
            VALUES("remark", "#{remark}");
            VALUES("version", "#{version}");
            VALUES("del_flag", DelFlagEnums.NORMAL.getCode());
        }}.toString() + " ON DUPLICATE KEY UPDATE update_time=NOW()";
    }
}
